Don't lint range syntax with var name start and/or end#2507
Don't lint range syntax with var name start and/or end#2507oli-obk merged 3 commits intorust-lang:masterfrom
start and/or end#2507Conversation
oli-obk
left a comment
There was a problem hiding this comment.
But I guess it's rare to write them explicitly.
I agree, still if we can detect this in a more general way it would be better
| impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantFieldNames { | ||
| fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { | ||
| if let ExprStruct(_, ref fields, _) = expr.node { | ||
| if let ExprStruct(ref path, ref fields, _) = expr.node { |
There was a problem hiding this comment.
Have you tried checking with the in_macro method? I think this should have expansion info, so we should be able to detect it that way
There was a problem hiding this comment.
I didn't know in_macro() until now.
But the method intends not to treat range expressions as "in_macro" (since #1373).
So I've added a method which determines whether an expression is a range expression.
https://github.com/rust-lang-nursery/rust-clippy/pull/2507/files#diff-5b47b8bbc8833f6268e936ea8682644dR68
Now range expressions are ignored, and hand-written Range family structs are treated normally by the lint.
There was a problem hiding this comment.
nice! The diff lgtm. Let's wait for travis and then merge
Hand-written `Range` struct family are treated normally.
Fixes #2491.
But this PR introduces new false-negative:
does not lint hand-written
Rangestruct family with var namestartand/orend,i.e.
std::ops::Range { start: start, end: end }But I guess it's rare to write them explicitly.